package com.heima.controller;

import com.heima.common.PageResult;
import com.heima.pojo.User;
import com.heima.pojo.dto.PageQueryDTO;
import com.heima.pojo.dto.PageUserQueryDTO;
import com.heima.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/user-service/user")
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping("/search")
    public PageResult userQuery(PageUserQueryDTO dto){
        log.info("人员搜索：{}",dto);
        return userService.userQuery(dto);
    }

    @PostMapping
    public Boolean save(@RequestBody User user){
        log.info("新增人员：{}",user);
        return userService.save(user);
    }


    @PutMapping("/{userId}")
    public Boolean update(@PathVariable Integer userId,@RequestBody User user){
        log.info("修改人员：{}，{}",userId,user);
        return userService.update(userId,user);
    }

    @DeleteMapping("/{userId}")
    public Boolean delete(@PathVariable Integer userId){
        log.info("删除人员：{}",userId);
        return userService.delete(userId);
    }

    @GetMapping("/{id}")
    public User queryUserById(@PathVariable Integer id){
        log.info("获取用户基本信息：{}",id);
        return userService.queryUserById(id);
    }

    @GetMapping("/searchUserWork")
    public PageResult searchUserWork(PageUserQueryDTO dto){
        log.info("人员工作量列表：{}",dto);
        return userService.searchUserWork(dto);
    }

}
